package com.airline.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.airline.beans.Employee;
import com.airline.connection.AirlineSystemServiceProxy;
import com.airline.form.EmployeeForm;

public class EmployeeAction extends DispatchAction{
	
	AirlineSystemServiceProxy proxy = new AirlineSystemServiceProxy();
	public ActionForward create(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		
		EmployeeForm empForm = (EmployeeForm)form;
		
		Employee emp = empForm.getEmp();
		
		emp.setPassword("123");
		// Check for duplicate employees
		
		String empId = proxy.createEmployee(emp);
		
		if(null == empId){
			
			empForm.setError("This is a duplicate employee record with these details");
			mapping.findForward("failure");
		}
		
		
		emp.setPersonID(empId);
		
		return mapping.findForward("success");
	}

	
	
	

}
